package com.mentalsurvey.controller;

import com.mentalsurvey.entity.Paper;
import com.mentalsurvey.mapper.PaperMapper;
import com.mentalsurvey.service.PaperService;
import com.mentalsurvey.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 试卷
 * @author vito
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/paper")
public class PaperController {
    @Autowired
    private PaperMapper paperMapper;

    @Autowired
    private PaperService paperService;
    @PostMapping("/create")
    public String createPaper(@RequestBody Paper paper) {
        System.out.println("paper"+paper.getPaperCode());
        paperMapper.insert(paper);
        return "试卷创建成功";
    }

    // 获取试卷列表
    @GetMapping("/list")
    public List<Paper> getPapers() {
        return paperMapper.selectAll();
    }
    @GetMapping("/getPapersById")
    public Paper getPapersById(@RequestParam("id") int id) {
        return paperMapper.selectById(id);
    }

    // 获取试卷
    @GetMapping("/details")
    public Result<?> getPaperDetails(@RequestParam("paperId") Integer paperId,
                                     @RequestParam("paperCode") String paperCode) {
        Map<String, Object> result = paperService.getPaperDetails(paperId, paperCode);
        if (result != null) {
            return Result.success("查询成功", result);
        } else {
            return Result.error("未找到相关数据");
        }
    }
}
